import Calculator.*;
import java.awt.Color;

public class NewJFrame extends javax.swing.JFrame {

    private NewJFrame() {
        super("GUI Calculator v.1.0"); setBounds(100,200,300,100);
        initComponents();
              
    }
    
    Sorter Sorter = new Sorter();
    
    // Operator Classes from package Calculator
    AddClass Add = new AddClass();
    SubtractClass Subtract = new SubtractClass();
    MultiClass Multiply = new MultiClass();
    DivideClass Divide = new DivideClass();
    ExpClass Exponent = new ExpClass();
    FactorialClass Factorial = new FactorialClass();
    
    // Private data types unique to NewJFrame Class
    private double answer = 0;
    private double largest = 0;
    private double smallest = 0;
    private double average = 0;
    private double sum = 0;
    

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        Operators = new javax.swing.ButtonGroup();
        TabFrame = new javax.swing.JTabbedPane();
        CalculatePanel = new javax.swing.JPanel();
        TextFieldA = new javax.swing.JTextField();
        TextFieldB = new javax.swing.JTextField();
        AddButton = new javax.swing.JToggleButton();
        SubButton = new javax.swing.JToggleButton();
        MultiButton = new javax.swing.JToggleButton();
        DivideButton = new javax.swing.JToggleButton();
        FactorialButton = new javax.swing.JToggleButton();
        ExpButton = new javax.swing.JToggleButton();
        ExitButton = new javax.swing.JButton();
        ClearButton = new javax.swing.JButton();
        CompButton = new javax.swing.JButton();
        AnswerLabel = new javax.swing.JLabel();
        LabelA = new javax.swing.JLabel();
        LabelB = new javax.swing.JLabel();
        ErrorLabel = new javax.swing.JLabel();
        SortPanel = new javax.swing.JPanel();
        SortTextField = new javax.swing.JTextField();
        LargestLabel = new javax.swing.JLabel();
        SortInstruc = new javax.swing.JLabel();
        SmallestLabel = new javax.swing.JLabel();
        AverageLabel = new javax.swing.JLabel();
        SortButton = new javax.swing.JButton();
        Clear2Button = new javax.swing.JButton();
        SumLabel = new javax.swing.JLabel();
        SortErrorLabel = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        TabFrame.setToolTipText("");

        Operators.add(AddButton);
        AddButton.setText("+");
        AddButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                AddButtonActionPerformed(evt);
            }
        });

        Operators.add(SubButton);
        SubButton.setText("-");
        SubButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                SubButtonActionPerformed(evt);
            }
        });

        Operators.add(MultiButton);
        MultiButton.setText("x");
        MultiButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                MultiButtonActionPerformed(evt);
            }
        });

        Operators.add(DivideButton);
        DivideButton.setText("÷");
        DivideButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                DivideButtonActionPerformed(evt);
            }
        });

        Operators.add(FactorialButton);
        FactorialButton.setText("!");
        FactorialButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                FactorialButtonActionPerformed(evt);
            }
        });

        Operators.add(ExpButton);
        ExpButton.setText("a^b");
        ExpButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ExpButtonActionPerformed(evt);
            }
        });

        ExitButton.setFont(new java.awt.Font("Calibri", 1, 14)); // NOI18N
        ExitButton.setText("Exit");
        ExitButton.setPreferredSize(new java.awt.Dimension(53, 30));
        ExitButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ExitButtonActionPerformed(evt);
            }
        });

        ClearButton.setFont(new java.awt.Font("Calibri", 0, 13)); // NOI18N
        ClearButton.setText("Clear");
        ClearButton.setMaximumSize(new java.awt.Dimension(61, 30));
        ClearButton.setMinimumSize(new java.awt.Dimension(61, 30));
        ClearButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ClearButtonActionPerformed(evt);
            }
        });

        CompButton.setFont(new java.awt.Font("Calibri", 0, 13)); // NOI18N
        CompButton.setText("Compute");
        CompButton.setMaximumSize(new java.awt.Dimension(81, 30));
        CompButton.setMinimumSize(new java.awt.Dimension(81, 30));
        CompButton.setPreferredSize(new java.awt.Dimension(81, 30));
        CompButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                CompButtonActionPerformed(evt);
            }
        });

        AnswerLabel.setFont(new java.awt.Font("Arial Narrow", 0, 18)); // NOI18N
        AnswerLabel.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        AnswerLabel.setText("[Answer]");
        AnswerLabel.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                AnswerLabelMouseClicked(evt);
            }
        });

        LabelA.setFont(new java.awt.Font("Calibri", 0, 14)); // NOI18N
        LabelA.setText("First Number");

        LabelB.setFont(new java.awt.Font("Calibri", 0, 14)); // NOI18N
        LabelB.setText("Second Number");

        ErrorLabel.setFont(new java.awt.Font("Cambria Math", 0, 14)); // NOI18N

        javax.swing.GroupLayout CalculatePanelLayout = new javax.swing.GroupLayout(CalculatePanel);
        CalculatePanel.setLayout(CalculatePanelLayout);
        CalculatePanelLayout.setHorizontalGroup(
            CalculatePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(CalculatePanelLayout.createSequentialGroup()
                .addGroup(CalculatePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(CalculatePanelLayout.createSequentialGroup()
                        .addGap(3, 3, 3)
                        .addGroup(CalculatePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(LabelA, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(LabelB, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addGap(26, 26, 26)
                        .addGroup(CalculatePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(TextFieldB, javax.swing.GroupLayout.PREFERRED_SIZE, 109, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(TextFieldA, javax.swing.GroupLayout.PREFERRED_SIZE, 109, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(29, 29, 29)
                        .addComponent(AddButton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(SubButton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(MultiButton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(DivideButton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(FactorialButton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(ExpButton))
                    .addGroup(CalculatePanelLayout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(CalculatePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(CalculatePanelLayout.createSequentialGroup()
                                .addComponent(ErrorLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 315, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(0, 0, Short.MAX_VALUE))
                            .addGroup(CalculatePanelLayout.createSequentialGroup()
                                .addComponent(ExitButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(ClearButton, javax.swing.GroupLayout.PREFERRED_SIZE, 69, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(CompButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 94, Short.MAX_VALUE)
                                .addComponent(AnswerLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 217, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                .addContainerGap())
        );
        CalculatePanelLayout.setVerticalGroup(
            CalculatePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(CalculatePanelLayout.createSequentialGroup()
                .addGroup(CalculatePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(CalculatePanelLayout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(CalculatePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(TextFieldA, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(LabelA))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(CalculatePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(TextFieldB, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(LabelB)))
                    .addGroup(CalculatePanelLayout.createSequentialGroup()
                        .addGap(33, 33, 33)
                        .addGroup(CalculatePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(SubButton)
                            .addComponent(MultiButton)
                            .addComponent(DivideButton)
                            .addComponent(FactorialButton)
                            .addComponent(AddButton)
                            .addComponent(ExpButton))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 35, Short.MAX_VALUE)
                .addComponent(ErrorLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(27, 27, 27)
                .addGroup(CalculatePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, CalculatePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(CompButton, javax.swing.GroupLayout.DEFAULT_SIZE, 35, Short.MAX_VALUE)
                        .addComponent(AnswerLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(ClearButton, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(ExitButton, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );

        TabFrame.addTab("Calculate", CalculatePanel);

        LargestLabel.setFont(new java.awt.Font("Century Schoolbook", 0, 14)); // NOI18N
        LargestLabel.setText("Largest:");

        SortInstruc.setFont(new java.awt.Font("Cambria Math", 0, 14)); // NOI18N
        SortInstruc.setText("Enter a list of 1 to 10  integers, separated by spaces. ^_^");

        SmallestLabel.setFont(new java.awt.Font("Century Schoolbook", 0, 14)); // NOI18N
        SmallestLabel.setText("Smallest:");

        AverageLabel.setFont(new java.awt.Font("Century Schoolbook", 0, 14)); // NOI18N
        AverageLabel.setText("Average:");

        SortButton.setFont(new java.awt.Font("Calibri", 0, 13)); // NOI18N
        SortButton.setText("Sort");
        SortButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                SortButtonActionPerformed(evt);
            }
        });

        Clear2Button.setFont(new java.awt.Font("Calibri", 0, 14)); // NOI18N
        Clear2Button.setText("Clear");
        Clear2Button.setMaximumSize(new java.awt.Dimension(61, 30));
        Clear2Button.setMinimumSize(new java.awt.Dimension(61, 30));
        Clear2Button.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                Clear2ButtonActionPerformed(evt);
            }
        });

        SumLabel.setFont(new java.awt.Font("Century Schoolbook", 0, 14)); // NOI18N
        SumLabel.setText("Sum:");

        SortErrorLabel.setFont(new java.awt.Font("Cambria Math", 0, 14)); // NOI18N

        javax.swing.GroupLayout SortPanelLayout = new javax.swing.GroupLayout(SortPanel);
        SortPanel.setLayout(SortPanelLayout);
        SortPanelLayout.setHorizontalGroup(
            SortPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(SortPanelLayout.createSequentialGroup()
                .addGap(19, 19, 19)
                .addGroup(SortPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(SortPanelLayout.createSequentialGroup()
                        .addComponent(SortErrorLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 279, Short.MAX_VALUE)
                        .addGap(248, 248, 248))
                    .addGroup(SortPanelLayout.createSequentialGroup()
                        .addComponent(LargestLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGap(18, 18, 18)
                        .addComponent(SmallestLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(AverageLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 121, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(SumLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(76, 76, 76))
                    .addGroup(SortPanelLayout.createSequentialGroup()
                        .addComponent(SortTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 423, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(SortButton)
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(SortPanelLayout.createSequentialGroup()
                        .addGroup(SortPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(Clear2Button, javax.swing.GroupLayout.PREFERRED_SIZE, 78, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(SortInstruc))
                        .addGap(0, 0, Short.MAX_VALUE))))
        );
        SortPanelLayout.setVerticalGroup(
            SortPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, SortPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(SortInstruc, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(10, 10, 10)
                .addGroup(SortPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(SortButton, javax.swing.GroupLayout.DEFAULT_SIZE, 27, Short.MAX_VALUE)
                    .addComponent(SortTextField))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED, 12, Short.MAX_VALUE)
                .addGroup(SortPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(LargestLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(SmallestLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(AverageLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(SumLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(SortErrorLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(Clear2Button, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        TabFrame.addTab("Sort", SortPanel);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(TabFrame)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(TabFrame)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents
    
    // Makes the second number TextField editable
    private void makeEditable(){
        
        if(TextFieldB.isEditable() == false){
            TextFieldB.setEditable(true);
            TextFieldB.setBackground(Color.WHITE);
        } 
    }
    // Displays error if result is over the double limit of 1.7E308
    private void catchInfinity(){
        
        if(answer > 1.7E308){
            answer = 0;
            ErrorLabel.setText("You exceded the limit! Try using smaller numbers.");
        }
    }
    
    private void ExpButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ExpButtonActionPerformed
       
        makeEditable();
        
    }//GEN-LAST:event_ExpButtonActionPerformed
    
    private void MultiButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_MultiButtonActionPerformed
        
        makeEditable();
        
    }//GEN-LAST:event_MultiButtonActionPerformed

    private void AddButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_AddButtonActionPerformed
        
        makeEditable();
        
    }//GEN-LAST:event_AddButtonActionPerformed

    // Clears all frields in Calculate Tab
    private void ClearButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ClearButtonActionPerformed

        TextFieldA.setText("");
        TextFieldB.setText("");
        ErrorLabel.setText("");
        AnswerLabel.setText("[Answer]");
        answer = 0;
    }//GEN-LAST:event_ClearButtonActionPerformed

    private void ExitButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ExitButtonActionPerformed

        System.exit(0);
    }//GEN-LAST:event_ExitButtonActionPerformed

    private void CompButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_CompButtonActionPerformed
        // Reset ErrorLabel; Set ErrorLabel to red in case of exception
        ErrorLabel.setForeground(Color.red);
        ErrorLabel.setText("");
        
        
        try{
            
            // Finds selected button and returns calculating method into answer
            if(AddButton.isSelected()){
                
                    answer = Add.add(TextFieldA.getText(), TextFieldB.getText());
                    catchInfinity();
            } 

             else if(SubButton.isSelected()){

                    answer = Subtract.subtract(TextFieldA.getText(), TextFieldB.getText());
                    catchInfinity();
             } 

             else if(MultiButton.isSelected()){

                    answer = Multiply.multiply(TextFieldA.getText(), TextFieldB.getText());
                    catchInfinity();
             }        

             else if(DivideButton.isSelected()){

                    answer = Divide.divide(TextFieldA.getText(), TextFieldB.getText());
                    catchInfinity();
             }        

             else if(ExpButton.isSelected()){

                    answer = Exponent.exponentiate(TextFieldA.getText(), TextFieldB.getText());
                    catchInfinity();  
             }    

             else if(FactorialButton.isSelected()){

                    answer = Factorial.factorise(TextFieldA.getText());
                    
                    // Restrict factorial to integer limit. 
                    if(answer == -1){
                        answer = 0;
                        ErrorLabel.setText("Your number must be between 0 and 12.");}
                }
             
             // If no selection
             else {

                 ErrorLabel.setText("Oops! You forgot to choose an operator!");
                 answer = 0;}
        }
        
        catch(NumberFormatException EX){
               
                ErrorLabel.setText("Error! Make sure you entered a whole number.");
                answer = 0;
                }
            
        finally{
            AnswerLabel.setText(Double.toString(answer));}      
        
    }//GEN-LAST:event_CompButtonActionPerformed

    private void SubButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SubButtonActionPerformed
        
        makeEditable();
        
    }//GEN-LAST:event_SubButtonActionPerformed
    
    private void FactorialButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_FactorialButtonActionPerformed

        TextFieldB.setEditable(false);
        TextFieldB.setBackground(Color.LIGHT_GRAY);
    }//GEN-LAST:event_FactorialButtonActionPerformed

    private void DivideButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_DivideButtonActionPerformed
        
        makeEditable();
       
    }//GEN-LAST:event_DivideButtonActionPerformed

    private void SortButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SortButtonActionPerformed
        
        SortErrorLabel.setText(null);
        SortErrorLabel.setForeground(Color.red);
        
        try{
            Sorter.makeArray(SortTextField.getText());

            average = Sorter.average();
            sum = Sorter.sum();
            largest = Sorter.largest();
            smallest = Sorter.smallest();

            LargestLabel.setText("Largest: " + Double.toString(largest));
            SmallestLabel.setText("Smallest: " + Double.toString(smallest));
            SumLabel.setText("Sum: " + Double.toString(sum));
            AverageLabel.setText("Average: " + Double.toString(average));
        
        } 
        
        catch(NumberFormatException | ArrayIndexOutOfBoundsException EX){
             
             SortErrorLabel.setText("Error! Enter a valid set of whole numbers");
        }
        
        finally{
            Sorter.clear();
        }
 
        
    }//GEN-LAST:event_SortButtonActionPerformed
    
    // Clear all fields in Sort Tab
    private void Clear2ButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_Clear2ButtonActionPerformed
        
        SortTextField.setText(null);
        LargestLabel.setText("Largest:");
        SmallestLabel.setText("Smallest:");
        AverageLabel.setText("Average:");
        SumLabel.setText("Sum:");
        SortErrorLabel.setText(null);
         
    }//GEN-LAST:event_Clear2ButtonActionPerformed
    
    private void AnswerLabelMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_AnswerLabelMouseClicked
        
        // Puts answer into TextField
        TextFieldB.setText("");
        TextFieldA.setText(String.valueOf(Double.toString(answer)));
    }//GEN-LAST:event_AnswerLabelMouseClicked

    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>
        
        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            @Override
            public void run() {
                new NewJFrame().setVisible(true);
            }
        });
    }
    
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JToggleButton AddButton;
    private javax.swing.JLabel AnswerLabel;
    private javax.swing.JLabel AverageLabel;
    private javax.swing.JPanel CalculatePanel;
    private javax.swing.JButton Clear2Button;
    private javax.swing.JButton ClearButton;
    private javax.swing.JButton CompButton;
    private javax.swing.JToggleButton DivideButton;
    private javax.swing.JLabel ErrorLabel;
    private javax.swing.JButton ExitButton;
    private javax.swing.JToggleButton ExpButton;
    private javax.swing.JToggleButton FactorialButton;
    private javax.swing.JLabel LabelA;
    private javax.swing.JLabel LabelB;
    private javax.swing.JLabel LargestLabel;
    private javax.swing.JToggleButton MultiButton;
    private javax.swing.ButtonGroup Operators;
    private javax.swing.JLabel SmallestLabel;
    private javax.swing.JButton SortButton;
    private javax.swing.JLabel SortErrorLabel;
    private javax.swing.JLabel SortInstruc;
    private javax.swing.JPanel SortPanel;
    private javax.swing.JTextField SortTextField;
    private javax.swing.JToggleButton SubButton;
    private javax.swing.JLabel SumLabel;
    private javax.swing.JTabbedPane TabFrame;
    private javax.swing.JTextField TextFieldA;
    private javax.swing.JTextField TextFieldB;
    // End of variables declaration//GEN-END:variables
}
